<?php

/**
 * This is the model class for table "lusi_members".
 *
 * The followings are the available columns in table 'lusi_members':
 * @property string $id
 * @property string $first_name
 * @property string $last_name
 * @property string $email
 * @property string $address
 * @property string $phone
 * @property string $post_code
 * @property string $refer_code
 * @property string $nric
 * @property integer $referrer_id
 * @property integer $is_member
 * @property string $title_code
 * @property integer $status
 * @property string $balance
 * @property string $created_date
 *
 * The followings are the available model relations:
 * @property Logins $logins
 * @property Titles $titleCode
 * @property RegisterredCourses[] $registerredCourses
 * @property Transactions[] $transactions
 */
class Members extends CActiveRecord
{
	/**
	 * @var string
	 */
	public $id;

	/**
	 * @var string
	 */
	public $first_name;

	/**
	 * @var string
	 */
	public $last_name;

	/**
	 * @var string
	 */
	public $email;

	/**
	 * @var string
	 */
	public $address;

	/**
	 * @var string
	 */
	public $phone;

	/**
	 * @var string
	 */
	public $post_code;

	/**
	 * @var string
	 */
	public $refer_code;

	/**
	 * @var string
	 */
	public $nric;

	/**
	 * @var integer
	 */
	public $referrer_id;

	/**
	 * @var integer
	 */
	public $is_member;

	/**
	 * @var string
	 */
	public $title_code;

	/**
	 * @var integer
	 */
	public $status;

	/**
	 * @var string
	 */
	public $balance;

	/**
	 * @var string
	 */
	public $created_date;


 	/**
	 * @var Logins
	 */
	 public $Logins;

 	/**
	 * @var Titles
	 */
	 public $Titles;

 	/**
	 * @var RegisterredCourses
	 */
	 public $RegisterredCourses;

 	/**
	 * @var Transactions
	 */
	 public $Transactions;

	/**
	 * Returns the static model of the specified AR class.
	 * @return Members the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'lusi_members';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('first_name, last_name, email, address, phone, nric, title_code, balance, created_date', 'required'),
			array('referrer_id, is_member, status', 'numerical', 'integerOnly'=>true),
			array('first_name, last_name, email', 'length', 'max'=>50),
			array('address', 'length', 'max'=>100),
			array('phone', 'length', 'max'=>15),
			array('post_code', 'length', 'max'=>5),
			array('refer_code, nric, title_code, balance', 'length', 'max'=>10),
			array('email', 'email','checkMX'=>true),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, first_name, last_name, email, address, phone, post_code, refer_code, nric, referrer_id, is_member, title_code, status, balance, created_date', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'logins' => array(self::HAS_ONE, 'Logins', 'member_id'),
			'titleCode' => array(self::BELONGS_TO, 'Titles', 'title_code'),
			'registerredCourses' => array(self::HAS_MANY, 'RegisterredCourses', 'member_id'),
			'transactions' => array(self::HAS_MANY, 'Transactions', 'member_id'),
			'referrer' => array(self::BELONGS_TO, 'Members', 'referrer_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'course_id' => 'Course Name',		 
			'id' => 'ID',
			'first_name' => 'First Name',
			'last_name' => 'Last Name',
			'email' => 'Email',
			'address' => 'Address',
			'phone' => 'Phone',
			'post_code' => 'Post Code',
			'refer_code' => 'Refer Code',
			'nric' => 'NRIC',
			'referrer_id' => 'Referrer',
			'is_member' => 'Member',
			'title_code' => 'Title Code',
			'status' => 'Activate',
			'balance' => 'Balance',
			'created_date' => 'Created Date',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	 
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('first_name',$this->first_name,true);
		$criteria->compare('last_name',$this->last_name,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('post_code',$this->post_code,true);
		$criteria->compare('refer_code',$this->refer_code,true);
		$criteria->compare('nric',$this->nric,true);
		$criteria->compare('referrer_id',$this->referrer_id);
		$criteria->compare('is_member',$this->is_member);
		$criteria->compare('title_code',$this->title_code,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('balance',$this->balance,true);
		$criteria->compare('created_date',$this->created_date,true);
		$criteria->compare('deleted',0,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}